package storerouter

import (
	"encoding/json"
	"github.com/gin-gonic/gin"
	"nodeseller/RabbitMQ"
	"nodeseller/datamodels"
	"nodeseller/repositories"
	"nodeseller/response"
)

//创建店铺路由
func CreateOrder(c *gin.Context)  {
	phone,err := c.Cookie("phone")
	if err != nil{
		response.Response1(c,1,"身份验证失败，请重新登陆t","")
		return
	}
	var storedata datamodels.Store
	c.ShouldBind(&storedata)
	storedata.PhoneNumber = phone
	rabbitmq := RabbitMQ.NewRabbitMQSimple("order")
	data,err := json.Marshal(storedata)
	if err != nil{
		response.Response1(c,1,"创建失败，请稍后再试5","")
		return
	}
	rabbitmq.PublishSimple(string(data))
	response.Response1(c,0,"创建成功","")
}
//查看自己的店铺
func FinSelfStoreAll(c *gin.Context)  {
	phone,err := c.Cookie("phone")
	if err != nil{
		response.Response1(c,1,"身份验证失败，请重新登陆t","")
		return
	}
	store := repositories.NewStoreManager()
	result,err := store.SelectByKey(phone)
	if err != nil{
		response.Response1(c,1,"数据丢失，请稍后重试","")
		return
	}
	response.Response1(c,0,"查找成功",result)
}